<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改专题管理')"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-subject-edit" th:object="${ccSubject}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">专题名称：</label>
            <div class="col-sm-8">
                <input name="subjectName" th:field="*{subjectName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">专题描述：</label>
            <div class="col-sm-8">
                <textarea name="subjectDesc" class="form-control">[[*{subjectDesc}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">专题banner图：</label>
            <div class="col-sm-8 fileinput fileinput-exists" data-provides="fileinput">
                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;">
                    <img th:src="*{subjectBanner}">
                </div>
                <div>
                        <span class="btn btn-white btn-file">
                            <span class="fileinput-new">选择图片</span>
                            <span class="fileinput-exists">更改</span>
                            <input id="subjectBanner" name="subjectBanner" type="file">
                        </span>
                    <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否启用：</label>
            <div class="col-sm-8">
                <label class="radio-box">
                    <input type="radio" value="0" th:checked="*{subjectIfEnable}==0?true:false" id="optionsRadios1"
                           name="subjectIfEnable">启用</label>
                <label class="radio-box">
                    <input type="radio" value="1" th:checked="*{subjectIfEnable}==1?true:false" id="optionsRadios2"
                           name="subjectIfEnable">未启用</label>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: jasny-bootstrap-js"/>
<script th:inline="javascript">
    var prefix = ctx + "subject/subject";
    $("#form-subject-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            // $.operate.save(prefix + "/edit", $('#form-subject-edit').serialize());
            var formData = new FormData();
            formData.append("id", $("[type=hidden]").val())
            formData.append('subjectName', $("[name=subjectName]").val());
            formData.append('subjectDesc', $("[name=subjectDesc]").val());
            formData.append('remark', $("[name=remark]").val());
            formData.append('subjectIfEnable', $("[name=subjectIfEnable]:checked").val());
            if (document.getElementById("subjectBanner").files[0] != undefined) {
                formData.append('file', $('#subjectBanner')[0].files[0]);
            }

            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }
</script>
</body>
</html>